﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using UnityEditor;
//using UnityEngine;
//using System.IO;
//using System.Text.RegularExpressions;
//using UnityEngine.UI;
//using Spark;

//public class AssetsEditorManager : AssetPostprocessor
//{
//    void OnPostprocessAllAssets (
//	                            String[] importedAssets,
//	                            String[] deletedAssets,
//	                            String[] movedAssets,
//	                            String[] movedFromAssetPaths)
//	{
//        Logger.Print("OnPostprocessAllAssets");
//		foreach(string str in importedAssets) {
//			Logger.Print("Reimported Asset: " + str);
//		}

//        foreach (string str in deletedAssets)
//        {
//            Logger.Print("Deleted Asset: " + str);
//		}

//		for (int i = 0; i < movedAssets.Length; i++) {
//            Logger.Print("Moved Asset: " + movedAssets[i] + " from: " + movedFromAssetPaths[i]);
//		}
//	}
//	void OnPostprocessAudio(AudioClip clip) {
//        if (assetPath.IndexOf("Assets/Civilization/Resources") >= 0){
//			AudioImporter audioImporter = assetImporter as AudioImporter;

//            // TODO:lihaojie
//#if UNITY_5
//#else
//            audioImporter.format = AudioImporterFormat.Compressed;
//			audioImporter.compressionBitrate = 64000;
//#endif
//			AssetDatabase.Refresh();
//		}
//	}
//    void OnPostprocessModel(GameObject obj)
//    {
//        if (assetPath.IndexOf("Assets/Civilization/Raw/Scene") >= 0)
//        {
//            ModelImporter importer = assetImporter as ModelImporter;
//            bool animFlag, fullMeshFlag, fullMeshFlag1, fullMeshFlag2;
//            animFlag = fullMeshFlag = fullMeshFlag1 = fullMeshFlag2 = false;

//            if (obj.name.EndsWith("_anim"))
//                animFlag = true;
//            else if (obj.name.EndsWith("_fullmesh"))
//                fullMeshFlag = true;
//            else if (obj.name.EndsWith("_fullmesh1"))
//                fullMeshFlag1 = true;
//            else if (obj.name.EndsWith("_fullmesh2"))
//                fullMeshFlag2 = true;
//            else if (obj.name.EndsWith("_animfullmesh"))
//                animFlag = fullMeshFlag = true;
//            else if (obj.name.EndsWith("_animfullmesh1"))
//                animFlag = fullMeshFlag1 = true;
//            else if (obj.name.EndsWith("_animfullmesh2"))
//                animFlag = fullMeshFlag2 = true;
//            if (!animFlag)
//            {
//                importer.importAnimation = false;
//                importer.animationType = ModelImporterAnimationType.None;
//            }
//            if (fullMeshFlag)
//                importer.meshCompression = ModelImporterMeshCompression.Medium;
//            else if (fullMeshFlag1)
//                importer.meshCompression = ModelImporterMeshCompression.Low;
//            else if (fullMeshFlag2)
//                importer.meshCompression = ModelImporterMeshCompression.Off;
//            else
//                importer.meshCompression = ModelImporterMeshCompression.High;
//            importer.isReadable = false;
//            importer.importBlendShapes = false;

//            // TODO:lihaojie
//#if UNITY_5
//#else
//            importer.splitTangentsAcrossSeams = false;
//#endif
//            importer.optimizeMesh = true;
//        }

//        AssetDatabase.Refresh();
//    }

//    void OnPostprocessTexture(Texture2D texture)
//    {
//        if (assetPath.IndexOf("Assets/SparkAssets/") >= 0)
//        {
//            TextureImporter textureImporter = assetImporter as TextureImporter;
//            //textureImporter.textureFormat = TextureImporterFormat.ARGB32;

//            //if (true)
//            {
//                textureImporter.textureType = TextureImporterType.Sprite;
//                string atlasName = Path.GetDirectoryName(assetPath);
//                if (atlasName.Length > 19)
//                {
//                    atlasName = assetPath.Substring(19, assetPath.Length - 19);
//                    int splitIndex = atlasName.IndexOf("/");
//                    if (splitIndex >= 0)
//                        atlasName = atlasName.Substring(0, splitIndex);
//                }
//                else atlasName = "";
//                textureImporter.spritePackingTag = atlasName;
//                textureImporter.mipmapEnabled = false;
//                textureImporter.spritePixelsPerUnit = 1;

//				textureImporter.textureType = TextureImporterType.Sprite;
//				//textureImporter.spriteImportMode = SpriteImportMode.Single;

//                string fileName = Path.GetFileName(assetPath);
//                string[] s = fileName.Split(new Char[] { '_' });
//                if (s[0].IndexOf("Button") != -1 && texture != null && Path.GetExtension(fileName) == ".png")
//                {
//                    CreateButton();
//                }
//                else if (s[0].IndexOf("Clip") != -1)
//                {
//                    Logger.Print("Clip");
//                    //System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(Path.GetFullPath(assetPath));
//                    textureImporter.spriteImportMode = SpriteImportMode.Multiple;

//                }
//            }
//        }
//        else if (assetPath.IndexOf("Assets/Civilization/Resources/iconTexture/") >= 0)
//        {
//            TextureImporter textureImporter = assetImporter as TextureImporter;
//            //textureImporter.textureFormat = TextureImporterFormat.ARGB32;

//            //if (true)
//            {
//                textureImporter.textureType = TextureImporterType.Advanced;
//				textureImporter.npotScale = TextureImporterNPOTScale.None;
//				textureImporter.isReadable = false;
//                //string atlasName = Path.GetDirectoryName(assetPath);
//                //if (atlasName.Length > 19)
//                //{
//                //    atlasName = assetPath.Substring(19, assetPath.Length - 19);
//                //    int splitIndex = atlasName.IndexOf("/");
//                //    if (splitIndex >= 0)
//                //        atlasName = atlasName.Substring(0, splitIndex);
//                //}
//                //else atlasName = "";
//                textureImporter.spritePackingTag = "";
//                textureImporter.mipmapEnabled = false;
//                textureImporter.spritePixelsPerUnit = 1;

//                //textureImporter.spriteImportMode = SpriteImportMode.Single;
//            }
//        }
//        else if (assetPath.IndexOf("Assets/Civilization/Raw/Scene") >= 0)
//        {
//            TextureImporter textureImporter = assetImporter as TextureImporter;
//            string fileName = System.IO.Path.GetFileNameWithoutExtension(assetPath);
//            if (!fileName.EndsWith("_rgb"))
//                textureImporter.textureFormat = TextureImporterFormat.AutomaticCompressed;
//        }

//        //AssetDatabase.SaveAssets();
//        AssetDatabase.Refresh();        
//        //Logger.Print("结束");
//    }

//    private void CreateButton()
//    {
//        /*TextureImporter textureImporter = assetImporter as TextureImporter;
//        string fileName = Path.GetFileName(assetPath);
//        string prefabPath = System.IO.Path.ChangeExtension(assetPath, ".prefab");

//        textureImporter.spriteImportMode = SpriteImportMode.Single;
//        textureImporter.spritePixelsPerUnit = 1;
//        textureImporter.spritesheet = null;
//        UnityEngine.Object[] sprites = AssetDatabase.LoadAllAssetsAtPath(assetPath);
//        if (sprites.Length == 0) return;
//        //btn
//        GameObject go = new GameObject();
//        if (GameObject.Find("Canvas") == null)
//        {
//            Debug.LogError("没有Canvas,无法创建按钮");
//            return;
//        }
//        go.transform.parent = GameObject.Find("Canvas").gameObject.transform;
        
//        go.transform.localScale = Vector3.one;
//        go.transform.localPosition = Vector3.zero;
//        go.name = fileName;

//        TabButton image = go.AddComponent<TabButton>();
//        image.sprite = sprites[1] as Sprite;
//        image.rectTransform.localPosition = Vector3.zero;
//        image.rectTransform.localScale = Vector3.one;
//        image.SetNativeSize();

//        //sprite
//        Button btn = go.AddComponent<Button>();
//        btn.transition = Selectable.Transition.None;
//        Navigation nav = new Navigation();
//        nav.mode = Navigation.Mode.None;
//        btn.navigation = nav;

//        //style
//        Style style = go.AddComponent<Style>();
//        style.stylePath = prefabPath;
        
//        //txt
//        GameObject txtGo = new GameObject();
//        //style
//        Style txtStyle = txtGo.AddComponent<Style>();
//        txtStyle.stylePath = prefabPath + "_txt";

//        txtGo.name = "txt";
//        txtGo.transform.parent = go.transform;
//        Text txt = txtGo.AddComponent<Text>();
//        RectTransform rectT = txtGo.GetComponent<RectTransform>();
//        rectT.anchoredPosition = Vector2.zero;
//        rectT.sizeDelta = new Vector2(go.GetComponent<RectTransform>().rect.width, go.GetComponent<RectTransform>().rect.height);
//        txtGo.transform.localScale = Vector3.one;
//        txtGo.transform.localPosition = Vector3.zero;

//        txt.fontSize = 20;
//        txt.text = "改我";
//        txt.fontStyle = FontStyle.Normal;
//        txt.alignment = TextAnchor.MiddleCenter;
//        txt.font = AssetDatabase.LoadAssetAtPath("Assets/Civilization/Resources/Font/STXIHEI.TTF", typeof(Font)) as Font;

//        SparkTools.SetLayer(go, LayerMask.NameToLayer("UI"));

//		if(Assets.Load<GameObject>(prefabPath) == null) {
//			PrefabUtility.CreatePrefab(prefabPath, go);
//		}

//        AssetDatabase.SaveAssets();
//        GameObject.DestroyImmediate(go);*/
//        throw new System.NotImplementedException("//song ,not defined type for 'style'"); 
//    }
//}
